package cn.tedu.zhxy.controller;


import cn.tedu.zhxy.entity.Teacher;
import cn.tedu.zhxy.service.TeacherService;
import cn.tedu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.TSFBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-20
 */
@RestController
@RequestMapping("sms/teacherController")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @PostMapping("saveOrUpdateTeacher")
    public  Result  saveOrUpdateTeacher(@RequestBody Teacher teacher){
        teacherService.saveOrUpdate(teacher);
        return Result.ok();
    }

    @DeleteMapping("deleteTeacher")
    public Result  deleteTeacher(@RequestBody List<Integer> ids){
        teacherService.removeByIds(ids);
        return  Result.ok();
    }

    @GetMapping("/getTeachers/{page}/{limit}")
    public Result getTeachers(@PathVariable Long  page, @PathVariable Long  limit, Teacher teacher){
       Page<Teacher> pageParam = new Page<>(page,limit);
        IPage<Teacher> list = teacherService.selectTeacher(pageParam,teacher);
        return   Result.ok(list);
    }

}

